package cn.wd.service.impl;

import cn.wd.domain.ReportTable;
import cn.wd.mapper.ReportTableMapper;
import cn.wd.page.PageResult;
import cn.wd.qo.QueryObject;
import cn.wd.service.IReportTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReportTableServiceImpl implements IReportTableService {

    private final ReportTableMapper mapper;

    public ReportTableServiceImpl(ReportTableMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void save(ReportTable obj) {
        mapper.insert(obj);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateById(ReportTable obj) {
        mapper.updateByPrimaryKey(obj);
    }

    @Override
    public ReportTable selectById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ReportTable> selectAll() {
        return mapper.selectAll();
    }

    @Override
        public PageResult<ReportTable> query(QueryObject qo) {
            Long count = mapper.selectForCount(qo);
            if (count == 0) {
                return PageResult.empty(qo.getCurrentPage(),qo.getPageSize());
            }
            List<ReportTable> list = mapper.selectForList(qo);
            return new PageResult<>(qo.getCurrentPage(),qo.getPageSize(),count,list);
        }
}
